package com.taotao.service.Impl;

import com.taotao.mapper.TbItemCatMapper;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.service.ItemCatService;
import com.taotaotao.common.pojo.EasyUIZreeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class ItemCatServiceImpl implements ItemCatService {
    @Autowired
    private TbItemCatMapper itemCatMapper;
    @Override
    public List<EasyUIZreeResult> getZreeNode(long pid) {
        //根据传递的id查询item_cat表
        TbItemCatExample example = new TbItemCatExample();
        //指定查询条件
        TbItemCatExample.Criteria criteria = example.createCriteria();
        criteria.andParentIdEqualTo(pid);
        List<TbItemCat> tbItemCats = itemCatMapper.selectByExample(example);
        //将数据封装到EasyUIZreeResult中
        List<EasyUIZreeResult> results = new ArrayList<>();
        for(TbItemCat tbItemCat : tbItemCats){
            EasyUIZreeResult zreeResult = new EasyUIZreeResult();
            zreeResult.setId(tbItemCat.getId());
            zreeResult.setText(tbItemCat.getName());
            zreeResult.setState(tbItemCat.getIsParent()?"closed":"open");
            results.add(zreeResult);
        }
        return results;
    }
}
